package com.ruoyi.voucher.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.VoucherDetail;
import com.ruoyi.voucher.service.IVoucherDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证明细Controller
 * 
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/voucher_detail")
public class VoucherDetailController extends BaseController
{
    @Autowired
    private IVoucherDetailService voucherDetailService;


    /**
     * 查询凭证明细列表
     */
    @RequiresPermissions("voucher:voucher_detail:list")
    @GetMapping("/list")
    public TableDataInfo list(VoucherDetail voucherDetail)
    {
        startPage();
        List<VoucherDetail> list = voucherDetailService.selectVoucherDetailList(voucherDetail);
        return getDataTable(list);
    }



    /**
     * 导出凭证明细列表
     */
    @RequiresPermissions("voucher:voucher_detail:export")
    @Log(title = "凭证明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherDetail voucherDetail)
    {
        List<VoucherDetail> list = voucherDetailService.selectVoucherDetailList(voucherDetail);
        ExcelUtil<VoucherDetail> util = new ExcelUtil<VoucherDetail>(VoucherDetail.class);
        util.exportExcel(response, list, "凭证明细数据");
    }



    /**
     * 获取凭证明细详细信息
     */
    @RequiresPermissions("voucher:voucher_detail:query")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(voucherDetailService.selectVoucherDetailByDetailId(detailId));
    }



    /**
     * 新增凭证明细
     */
    @RequiresPermissions("voucher:voucher_detail:add")
    @Log(title = "凭证明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoucherDetail voucherDetail)
    {
        return toAjax(voucherDetailService.insertVoucherDetail(voucherDetail));
    }



    /**
     * 修改凭证明细
     */
    @RequiresPermissions("voucher:voucher_detail:edit")
    @Log(title = "凭证明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherDetail voucherDetail)
    {
        return toAjax(voucherDetailService.updateVoucherDetail(voucherDetail));
    }



    /**
     * 删除凭证明细
     */
    @RequiresPermissions("voucher:voucher_detail:remove")
    @Log(title = "凭证明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(voucherDetailService.deleteVoucherDetailByDetailIds(detailIds));
    }
}
